package com.jhl.seckill.controller;


import com.jhl.seckill.entity.User;
import com.jhl.seckill.service.OrderService;
import com.jhl.seckill.vo.OrderDetailVo;
import com.jhl.seckill.vo.RespBean;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

@ApiOperation("订单接口")
@RequestMapping("/order")
@Slf4j
@Controller
public class OrderController {

    @Autowired
    OrderService orderService;

    @RequestMapping(value = "/detail/{orderId}", method = RequestMethod.GET)
    @ResponseBody
    public RespBean orderDetail(@PathVariable Long orderId, HttpServletRequest request) throws Exception {
        /**
         * 订单详情由网关控制，已经对token进行了验证，那么这里肯定可以获取到
         */
        String username = request.getHeader("user");
        User user = new User();
        user.setUsername(username);

//        if(user==null){
//            return RespBean.error(RespBeanEnum.SESSION_ERROR);
//        }

//        根据订单ID查询订单
        OrderDetailVo orderDetailVo = orderService.detail(orderId);
        return RespBean.success(orderDetailVo);

    }
}
